package dbinit;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;

import core.profile.model.SecurityQuestion;
import core.util.HibernateCoreUtil;

public class InitSecurityQuestion 
{
	public static SecurityQuestion getSecurityQuestionByUuid(Long uuid)
	{
		SecurityQuestion sq = null ;
		Session session = HibernateCoreUtil.getSessionFactory().openSession();
		Transaction transaction = null;
		try 
		{
				transaction = session.beginTransaction();
				sq = (SecurityQuestion) session.get(SecurityQuestion.class, uuid);
				transaction.commit();
		}
		catch (HibernateException e) 
		{
			// TODO: handle exception
			transaction.rollback();
			e.printStackTrace();
		}
		finally 
		{
			session.close();
		}
		return sq ;
	}
	public static Long doinit(String question)
	{
		Transaction transaction = null;
		Session session = HibernateCoreUtil.getSessionFactory().openSession();
		SecurityQuestion sq = new SecurityQuestion();
		sq.setSeq1(question);
		Long uuid = null;
		try
		{
			transaction = session.beginTransaction();
		    uuid = (Long)session.save(sq);
			transaction.commit();
		}
		catch(HibernateException he)
		{
			he.printStackTrace();
		}
		return uuid ;
	}

}
